using System;
using UnityEditor.Experimental.GraphView;
using UnityEngine;
using UnityEngine.UIElements;

namespace Framework.Fsm
{
    public class FsmEntryPointNode : Node
    {
        public FsmUserData Data { get; private set; }
        public Port outputPort { get; private set; }
        private TextField title_input;
        private FsmGraphContext _context;
        public void Initialize(FsmGraphContext context)
        {
            _context = context;
            Data = new FsmUserData() { Id = Guid.NewGuid().ToString(), DataType = UserDataType.Entry, Target = this };
            title = "入口";
            inputContainer.visible = false;
            outputPort = Port.Create<Edge>(Orientation.Horizontal, Direction.Output, Port.Capacity.Single, typeof(Port));
            outputPort.userData = Data;
            outputPort.portName = "";
            outputContainer.Add(outputPort);
            this.capabilities -= Capabilities.Deletable;
            this.capabilities -= Capabilities.Droppable;
            title_input = new TextField()
            {
                value = "FsmStateAction"
            };
            title_input.RegisterValueChangedCallback(evt =>
            {
                SetActionType(evt.newValue);
            });
            Add(title_input);
            this.SetPosition(new Rect(new Vector2(100, 100), new Vector2(100, 100)));
            this.RefreshExpandedState();
            this.RefreshPorts();
        }
        public void SetActionType(string value)
        {
            title_input.value = value.Trim();
            var type = FsmProvider.GetTypeByName(value);
            if (type != null)
            {

            }
            _context.ActionType = type;
            _context.ActionSearchProvider.Initialize(_context);
        }
    }
}